package com.github.glomadrian.materialanimatedswitch.painter;

import com.github.glomadrian.materialanimatedswitch.utils.PixelMapUtils;
import com.github.glomadrian.materialanimatedswitch.utils.Utils;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.PixelMapHolder;
import ohos.app.Context;
import ohos.media.image.PixelMap;

public abstract class IconPainter implements SwitchInboxPinnedPainter {
    protected PixelMap iconBitmap;
    protected Context context;
    protected Paint paint;
    protected int width;
    protected int height;
    protected int imageHeight;
    protected int imageWidth;
    protected boolean isVisible = false;
    protected int iconXPosition;
    protected int iconYPosition;
    protected int margin;

    public IconPainter(Context context, PixelMap bitmap, int margin) {
        this.context = context;
        this.iconBitmap = bitmap;
        this.margin = margin;
        init();
    }

    private void init() {
        paint = new Paint();
        initBitmap();
    }

    protected void initBitmap() {
        int iconSize = Utils.vp2px(context, 11);
        iconBitmap = PixelMapUtils.createScaledBitmap(iconBitmap, iconSize, iconSize, false);
        imageHeight = iconBitmap.getImageInfo().size.height;
        imageWidth = iconBitmap.getImageInfo().size.width;
    }

    @Override
    public void draw(Canvas canvas) {
        if (isVisible) {
            canvas.drawPixelMapHolder(new PixelMapHolder(iconBitmap),
                    iconXPosition,
                    iconYPosition,
                    paint);
        }
    }

    @Override
    public void onSizeChanged(int height, int width) {
        this.height = height;
        this.width = width;
    }
}
